package com.zdkj.subway.stm.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.zdkj.common.core.constant.CommonConstants;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 基础Bean中公用属性填充处理类
 * @author Administrator
 */
@Component
public class SubwayStmMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        PigxUser user = SecurityUtils.getUser();
        if (null != user) {
            this.setFieldValByName("creatorId", user.getId(), metaObject);
            this.setFieldValByName("creatorName", user.getNikeName(), metaObject);
            this.setFieldValByName("creatorCode", user.getUserCode(), metaObject);
            this.setFieldValByName("deptId", user.getDeptId(), metaObject);
            this.setFieldValByName("lineCode", user.getLineCode(), metaObject);
            this.setFieldValByName("stationCode", user.getStationCode(), metaObject);
        }
        this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
        this.setFieldValByName("delFlag", CommonConstants.STATUS_NORMAL, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
    }
}
